// struct: 结构嵌套

#include <stdio.h>

struct point
{
    int x;
    int y;
};

struct rectangle
{
    struct point pt1;
    struct point pt2;
};

void printRect(struct rectangle);

int main(int argc, char const *argv[])
{
    // 如果有变量定义：
    struct rectangle r, *rp;
    rp = &r;
    // 则以下四种形式是等价的
    // r.pt1.x
    // rp->pt1.x
    // (r.pt1).x
    // (rp->pt1).x

    struct rectangle rects[] = {
        {{1, 2}, {3, 4}}, 
        {{5, 6}, {7, 8}}, 
    };

    for (int i = 0; i < 2; i++)
    {
        printRect(rects[i]);
    }

    printf("%d\n", sizeof(rects));
    printf("%d\n", sizeof(rects[0]));

    // 看来结构体数组也是指针
    printf("%p\n", rects);
    printf("%p\n", &rects);
    
    return 0;
}

void printRect(struct rectangle r)
{
    printf("<%d, %d> to <%d, %d>\n", r.pt1.x, r.pt1.y, r.pt2.x, r.pt2.y);
}